package com.gettong.test.SpringCloudFeignProvider.controller;

import com.gettong.test.SpringCloudCommon.entity.User;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by gettong on 2019/11/30.
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @GetMapping("/list")
    public List<User> list() {
        List<User> userList = new ArrayList<>();
        User user1 = new User(1L, "gettong1", 18);
        User user2 = new User(2L, "gettong2", 20);
        userList.add(user1);
        userList.add(user2);
        return userList;
//        throw new RuntimeException("发生异常拉！！！");
    }

    @GetMapping("/{id}")
    public User get(@PathVariable("id") Long id) {
        System.out.println(id);
        User user = new User(1L, "gettong1", 18);
        return user;
    }

    @PostMapping("/")
    public void save(@RequestBody User user) {
        System.out.println(user);
    }

    @DeleteMapping("/{id}")
    public void delete(@PathVariable("id") Long id) {
        System.out.println(id);
    }

}
